Switch Board is a MVC framework written for PHP. Its original concepts were taken from a preexisting ColdFusion/PHP framework called Fusebox. Its evolution through development has greatly changed its structure to have very little resemblance to Fusebox other than slight functionality of the switch, settings and template files.
Contents |
The current release of Switch Board is Switch Board with Routing 2.0.1. This version was released on December 25, 2006 by the developer Daniel Slaughter.
Switch Board has three sub-directories from its root. These sub-directories are the control, model and view. When a page is called from a Browser the PHP Server executes the control, model and then view file before displaying the resulting content to the called Browser. This separation of MVC is seamless to the end user.
The core file is the brains behind everything. This file (sb_core.php) consists of 66 lines of code. The core file executes in the following manner:
The settings is held in a file called sb_settings.php in the root of the Switch Board files. This file is where any global variables are held. For instance, the configuration variables of Switch Board are located here. You may add any additional variables you wish to this file that your application will use. The settings file are called prior to any other file from the sb_core.php file.
The switch is held in a file called sb_switch.php in the root of the Switch Board files. This file is a simple PHP switch-case that handles any global variables to the individual page (such as the page title, if the page redirects, and exit actions: links from this page). Please note: you do not need to have include statements for the control/model/view files here. Switch Board assumes if they exist they should be included (this greatly increases development time and ensures file naming schemes). The switch file is called before the control/model/view files are included.
Processes and responds to events, typically user actions, and may invoke changes on the model. In Switch Board the control is meant to make inserts/updates to a database or other file structure. These pages are typically called from the posting of a form.
The model is another name for the domain layer. The model in Switch Board is where database select statements are pooled. Calculations can also be done here to data before it is presented to the view file for display.
Renders the model into a form suitable for interaction, typically a user interface element. In Switch Board the view page contains the display generated from the data retrieved in the model. Only the information physically presented to the Browser should be held here (such as XHTML, HTML, CSS). However, for debugging purposes content can be displayed to the Browser through the control and model but is not suggested for final release.
The template is held in a file called sb_template.php in the root of the Switch Board files. This template file contains the wrapper XHTML/HTML for the content generated from a page call to Switch Board from the Browser. The template is the last file to include. There are parameters you can use to ignore the template (ie: $sb['useTemplate'] = false).
Hello World
You can then access this Hello World application by going to an address such as: http://domain.com/helloworld.htm
$sb['redirect'] = "http://domain.com/control/page.htm";
// turn on/off authentication $sb['useAuthentication'] = true // what variable to check if it exists (such as a session that only exists if they're "logged in") $sb['hasAuthentication'] = isSet($_SESSION['auth']); // the array of pages you should only be able to access without authentication: include circuitpath/extension $sb['noAuthentication'] = array("index.htm","apple.htm"); // you will be redirected here if you attempt to access an internal page that you do not have authentication to $sb['noAuthenticationRedirect'] = "/sb_20/index.htm?error=authentication"; // if you are authenticated and attempt to access a non-authenticated page, redirect to here (such as the login page) $sb['authenticationRedirect'] = "/sb_20/hasauthentication.htm";
$sb['useTemplate'] = true; $sb['useControl'] = true; $sb['useModel'] = true; $sb['useView'] = true;
// this page will be included if someone types in an incorrect page address. $sb['errorPage'] = "error404";
$sb['fileExt'] = ".htm"; $sb['defaultPage'] = "index";